package vip.aster.workflow.vo;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import vip.aster.workflow.entity.WfApp;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 应用管理
 *
 * @author Aster lipian1004@163.com
 * @since 2024-05-11 09:48:46
 */
@Data
@Schema(description = "应用管理")
public class WfAppVO implements Serializable {

	@Serial
	private static final long serialVersionUID = 1L;

	@Schema(description = "主键")
	private String id;
	@Schema(description = "应用名称")
	private String name;
	@Schema(description = "图标")
	private String icon;
	@Schema(description = "图标颜色")
	private String iconColor;
	@Schema(description = "排序")
	private Integer sort;
	@Schema(description = "租户ID")
	private String tenantId;
	@Schema(description = "版本号")
	private Integer version;
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@Schema(description = "创建时间")
	private LocalDateTime createTime;
	@Schema(description = "创建者")
	private String createBy;
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@Schema(description = "更新时间")
	private LocalDateTime updateTime;
	@Schema(description = "修改者")
	private String updateBy;
	@Schema(description = "启用状态")
	private String status;
	@Schema(description = "删除状态")
	private String isDeleted;
	@Schema(description = "备注信息")
	private String remark;

	public WfAppVO() {
		super();
	}

	public WfAppVO(WfApp entity) {
		this.id = entity.getId();
		this.name = entity.getName();
		this.icon = entity.getIcon();
		this.iconColor = entity.getIconColor();
		this.sort = entity.getSort();
		this.tenantId = entity.getTenantId();
		this.version = entity.getVersion();
		this.createTime = entity.getCreateTime();
		this.createBy = entity.getCreateBy();
		this.updateTime = entity.getUpdateTime();
		this.updateBy = entity.getUpdateBy();
		this.status = entity.getStatus();
		this.isDeleted = entity.getIsDeleted();
		this.remark = entity.getRemark();
	}

	public static List<WfAppVO> convertList(List<WfApp> source) {
		if (CollUtil.isEmpty(source)) {
			return ListUtil.empty();
		}
		List<WfAppVO> list = new ArrayList<>();
		for (WfApp entity : source) {
			list.add(new WfAppVO(entity));
		}
		return list;
	}

	public WfApp reconvert() {
		WfApp entity = new WfApp();
		entity.setId(this.id);
		entity.setName(this.name);
		entity.setIcon(this.icon);
		entity.setIconColor(this.iconColor);
		entity.setSort(this.sort);
		entity.setTenantId(this.tenantId);
		entity.setVersion(this.version);
		entity.setCreateTime(this.createTime);
		entity.setCreateBy(this.createBy);
		entity.setUpdateTime(this.updateTime);
		entity.setUpdateBy(this.updateBy);
		entity.setStatus(this.status);
		entity.setIsDeleted(this.isDeleted);
		entity.setRemark(this.remark);
		return entity;
	}

}
